package com.liveneo.adapter.mobile.util;

import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class DesBase64Util {
	/**
	 * 加密
	 * @param deskey
	 * @return
	 */
	public static String encode(String deskey){
		if(deskey != null && !"".equals(deskey)){
			BASE64Encoder encoder = new BASE64Encoder();
			String desresult =  encoder.encode(DesUtil.encryptMode(deskey.getBytes()));
			return desresult;
		}
		return null;
	}
	/**
	 * 解密
	 * @param desresult
	 * @return
	 */
	public static String decoder(String desresult){
		BASE64Decoder decoder = new BASE64Decoder();
		String result = null;
		try {
			byte[] resGzipXML = decoder.decodeBuffer(desresult);
			result = new String(DesUtil.decryptMode(resGzipXML));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	public static void main(String[] args) {
		String t1 = encode("master");
//		String t2 = decoder(t1);
		
		System.out.println(t1);
		
		System.out.println(decoder("bTNd2pOeSZPHf7+8ciUYCKUwfqlwaJx6"));
		
		
//		System.out.println(t1);
//		System.out.println(t2);
	}
}
